import type { RouteRecordRaw } from 'vue-router'
import { adminBaseRoutePath } from '/@/router/static/adminBase'
import { memberCenterBaseRoutePath } from '/@/router/static/memberCenterBase'

const pageTitle = (name: string): string => {
    return `pagesTitle.${name}`
}

/*
 * 静态路由
 * 自动加载 ./static 目录的所有文件，并 push 到以下数组
 */
const staticRoutes: Array<RouteRecordRaw> = [
    {
        // 九型人格测试首页
        path: '/',
        name: '/',
        component: () => import('/@/views/frontend/enneagram/container.vue'),
        redirect: '/index',
        meta: {
            title: '九型人格测试',
        },
        children: [
            {
                path: 'index',
                name: 'index',
                component: () => import('/@/views/frontend/enneagram/index.vue'),
                meta: {
                    title: '九型人格测试-做题',
                },
            },
            {
                path: 'result/:id(\\d+)',
                name: 'result',
                component: () => import('/@/views/frontend/enneagram/enneagramResult.vue'),
                meta: {
                    title: '九型人格测试-报告',
                },
            },
            {
                path: 'pay/:id(\\d+)',
                name: 'pay',
                component: () => import('/@/views/frontend/enneagram/pay.vue'),
                meta: {
                    title: '九型人格测试-支付',
                },
            },
        ],
    },
    {
        // 九型人格测试海报
        path: '/register',
        name: 'register',
        component: () => import('../views/frontend/enneagram/register.vue'),
        meta: {
            title: '九型人格测试-注册',
        },
    },
    {
        // 九型人格测试海报
        path: '/login',
        name: 'login',
        component: () => import('../views/frontend/enneagram/login.vue'),
        meta: {
            title: '九型人格测试-登陆',
        },
    },
    {
        // 九型人格测试海报
        path: '/poster/:id(\\d+)',
        name: 'poster',
        component: () => import('/@/views/frontend/enneagram/poster.vue'),
        meta: {
            title: '九型人格测试',
        },
    },
    {
        // 九型人格测试首页
        path: '/second',
        name: 'second',
        component: () => import('/@/views/frontend/enneagram/second.vue'),
        meta: {
            title: '九型人格测试',
        },
    },
    // {
    //     // 首页
    //     path: '/index',
    //     name: 'index',
    //     component: () => import('/@/views/frontend/index.vue'),
    //     meta: {
    //         title: '首页',
    //     },
    // },

    // {
    //     // 首页
    //     path: memberCenterBaseRoutePath + '/education',
    //     name: 'education',
    //     component: () => import('/@/views/frontend/yimin/education.vue'),
    //     meta: {
    //         title: '寰宇教育',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/about',
    //     name: 'about',
    //     component: () => import('/@/views/frontend/yimin/about.vue'),
    //     meta: {
    //         title: '关于我们',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/america',
    //     name: 'america',
    //     component: () => import('/@/views/frontend/yimin/america.vue'),
    //     meta: {
    //         title: '美洲移民',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/areas',
    //     name: 'areas',
    //     component: () => import('/@/views/frontend/yimin/areas.vue'),
    //     meta: {
    //         title: '移民区域',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/asia-africa-special',
    //     name: 'asia-africa-special',
    //     component: () => import('/@/views/frontend/yimin/asia-africa-special.vue'),
    //     meta: {
    //         title: '亚非特别移民',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/asia-africa',
    //     name: 'asia-africa',
    //     component: () => import('/@/views/frontend/yimin/asia-africa.vue'),
    //     meta: {
    //         title: '亚非移民',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/europe',
    //     name: 'europe',
    //     component: () => import('/@/views/frontend/yimin/europe.vue'),
    //     meta: {
    //         title: '欧洲移民',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/list-asia-africa',
    //     name: 'list-asia-africa',
    //     component: () => import('/@/views/frontend/yimin/list-asia-africa.vue'),
    //     meta: {
    //         title: '亚非移民列表',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/list-education',
    //     name: 'list-education',
    //     component: () => import('/@/views/frontend/yimin/list-education.vue'),
    //     meta: {
    //         title: '教育移民列表',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/list-europe',
    //     name: 'list-europe',
    //     component: () => import('/@/views/frontend/yimin/list-europe.vue'),
    //     meta: {
    //         title: '欧洲移民列表',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/list-news',
    //     name: 'list-news',
    //     component: () => import('/@/views/frontend/yimin/list-news.vue'),
    //     meta: {
    //         title: '新闻列表',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/list-oceania',
    //     name: 'list-oceania',
    //     component: () => import('/@/views/frontend/yimin/list-oceania.vue'),
    //     meta: {
    //         title: '大洋洲移民列表',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/list-property',
    //     name: 'list-property',
    //     component: () => import('/@/views/frontend/yimin/list-property.vue'),
    //     meta: {
    //         title: '房产移民列表',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/list-study-abroad',
    //     name: 'list-study-abroad',
    //     component: () => import('/@/views/frontend/yimin/list-study-abroad.vue'),
    //     meta: {
    //         title: '留学移民列表',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/list-usa',
    //     name: 'list-usa',
    //     component: () => import('/@/views/frontend/yimin/list-usa.vue'),
    //     meta: {
    //         title: '美国移民列表',
    //     },
    // },

    // {
    //     path: memberCenterBaseRoutePath + '/news',
    //     name: 'news',
    //     component: () => import('/@/views/frontend/yimin/news.vue'),
    //     meta: {
    //         title: '新闻',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/oceania-bat',
    //     name: 'oceania-bat',
    //     component: () => import('/@/views/frontend/yimin/oceania-bat.vue'),
    //     meta: {
    //         title: '大洋洲BAT移民',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/oceania',
    //     name: 'oceania',
    //     component: () => import('/@/views/frontend/yimin/oceania.vue'),
    //     meta: {
    //         title: '大洋洲移民',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/property',
    //     name: 'property',
    //     component: () => import('/@/views/frontend/yimin/property.vue'),
    //     meta: {
    //         title: '房产移民',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/public',
    //     name: 'public',
    //     component: () => import('/@/views/frontend/yimin/public.vue'),
    //     meta: {
    //         title: '公共移民',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/study-abroad',
    //     name: 'study-abroad',
    //     component: () => import('/@/views/frontend/yimin/study-abroad.vue'),
    //     meta: {
    //         title: '留学移民',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/view-america',
    //     name: 'view-america',
    //     component: () => import('/@/views/frontend/yimin/view-america.vue'),
    //     meta: {
    //         title: '查看美洲移民',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/view-asia-africa',
    //     name: 'view-asia-africa',
    //     component: () => import('/@/views/frontend/yimin/view-asia-africa.vue'),
    //     meta: {
    //         title: '查看亚非移民',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/view-europe',
    //     name: 'view-europe',
    //     component: () => import('/@/views/frontend/yimin/view-europe.vue'),
    //     meta: {
    //         title: '查看欧洲移民',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/view-news',
    //     name: 'view-news',
    //     component: () => import('/@/views/frontend/yimin/view-news.vue'),
    //     meta: {
    //         title: '查看新闻',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/view-oceania',
    //     name: 'view-oceania',
    //     component: () => import('/@/views/frontend/yimin/view-oceania.vue'),
    //     meta: {
    //         title: '查看大洋洲移民',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/view-property',
    //     name: 'view-property',
    //     component: () => import('/@/views/frontend/yimin/view-property.vue'),
    //     meta: {
    //         title: '查看房产移民',
    //     },
    // },
    // {
    //     path: memberCenterBaseRoutePath + '/view-study-abroad',
    //     name: 'view-study-abroad',
    //     component: () => import('/@/views/frontend/yimin/view-study-abroad.vue'),
    //     meta: {
    //         title: '查看留学移民',
    //     },
    // },

    {
        // 管理员登录页 - 不放在 adminBaseRoute.children 因为登录页不需要使用后台的布局
        path: adminBaseRoutePath + '/login',
        name: 'adminLogin',
        component: () => import('/@/views/backend/login.vue'),
        meta: {
            title: pageTitle('adminLogin'),
        },
    },
    {
        // 会员登录页
        path: memberCenterBaseRoutePath + '/login',
        name: 'userLogin',
        component: () => import('/@/views/frontend/user/login.vue'),
        meta: {
            title: pageTitle('userLogin'),
        },
    },
    {
        path: '/:path(.*)*',
        redirect: '/404',
    },
    {
        // 404
        path: '/404',
        name: 'notFound',
        component: () => import('/@/views/common/error/404.vue'),
        meta: {
            title: pageTitle('notFound'), // 页面不存在
        },
    },
    {
        // 后台找不到页面了-可能是路由未加载上
        path: adminBaseRoutePath + ':path(.*)*',
        redirect: (to) => {
            return {
                name: 'adminMainLoading',
                params: {
                    to: JSON.stringify({
                        path: to.path,
                        query: to.query,
                    }),
                },
            }
        },
    },
    {
        // 会员中心找不到页面了
        path: memberCenterBaseRoutePath + ':path(.*)*',
        redirect: (to) => {
            return {
                name: 'userMainLoading',
                params: {
                    to: JSON.stringify({
                        path: to.path,
                        query: to.query,
                    }),
                },
            }
        },
    },
    {
        // 无权限访问
        path: '/401',
        name: 'noPower',
        component: () => import('/@/views/common/error/401.vue'),
        meta: {
            title: pageTitle('noPower'),
        },
    },
]

const staticFiles: Record<string, Record<string, RouteRecordRaw>> = import.meta.glob('./static/*.ts', { eager: true })
for (const key in staticFiles) {
    if (staticFiles[key].default) staticRoutes.push(staticFiles[key].default)
}

export default staticRoutes
